/**
 *
 */
package org.text2diagram.nlp.opennlp;

import java.io.IOException;

import opennlp.tools.lang.english.SentenceDetector;

import org.text2diagram.nlp.core.NLPDetector;
import org.text2diagram.nlp.core.NLPException;

/**
 * @author alex
 *
 */
public final class OpenNLPSentenceDetector implements NLPDetector<String,String[]> {

	/**
	 * Instance of OpenNLPSentence detector.
	 * TODO: lazy load.
	 */
	private static OpenNLPSentenceDetector detector = new OpenNLPSentenceDetector();

	/**
     * English sentence detector.
     */
    private SentenceDetector sentenceDetector;

    /**
     * Get sentence detector instance.
     * @return
     */
    public static OpenNLPSentenceDetector getInstance() {
    	return detector;
    }

    /**
     * Initialize sentence detector instance.
     */
	private OpenNLPSentenceDetector() {
		super();
		try {
			sentenceDetector = new SentenceDetector("resources/models/opennlp/english/sentdetect/EnglishSD.bin.gz");
		} catch (IOException e) {
			//TODO: correct catch
			e.printStackTrace();
		}
	}

	@Override
	public String[] detect(final String aText) throws NLPException {
		return sentenceDetector.sentDetect(aText);
	}

}
